import requests


def setup_function():
    pass


def teardown_function():
    pass

class Test_weidu():
    uid=""
    sid=""
    def setup_function(self):
        pass
    def teardown_function(self):
        pass
    # 登录
    def test_login(self):
        url="http://10.59.9.18/small/user/v1/login"
        data={"phone":"13811033965","pwd":"123456Aa"}
        r=requests.post(url=url,json=data)
        print(r.json())
        Test_weidu.uid=r.json()['result']['userId']
        Test_weidu.sid = r.json()['result']['sessionId']
    #新增收货地址
    def test_address(self):
        url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
        tou={"sessionId":Test_weidu.sid,"userId":str(Test_weidu.uid)}
        data={"realName":"张三","phone":"13811033965","address":"北京 海淀区 八维","zipCode":"101010"}
        r=requests.post(url=url,headers=tou,params=data)
        print(r.json())
        assert "添加成功" in r.json()['message']
    def test_address2(self):
        url = "http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
        tou = {"sessionId": Test_weidu.sid, "userId": str(Test_weidu.uid)}
        data = {"realName": "张三", "phone": " ", "address": "北京 海淀区 八维", "zipCode": "101010"}
        r = requests.post(url=url, headers=tou, params=data)
        print(r.json())
        assert "请正确填写手机号" in r.json()['message']
    def test_address3(self):
        url = "http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
        tou = {"sessionId": Test_weidu.sid, "userId": str(Test_weidu.uid)}
        data = {"realName": "张三", "phone": "13811033965", "address": "北京 海淀区 八维"}
        r = requests.post(url=url, headers=tou, params=data)
        print(r.json())
        assert "添加成功" not in r.json()['message']
    def test_address4(self):
        url = "http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
        tou = {"sessionId": Test_weidu.sid, "userId": str(Test_weidu.uid)}
        data = {"realName": " ", "phone": "13811033965", "address": "北京 海淀区 八维", "zipCode": "101010"}
        r = requests.post(url=url, headers=tou, params=data)
        print(r.json())
        assert "添加成功" in r.json()['message']